package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
public class SecurityConfiguration {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

        http.authorizeHttpRequests((requests) -> requests
                        .requestMatchers("/mylogin", "/getUser").permitAll()
                        .anyRequest().authenticated())
                .formLogin(withDefaults())
                .csrf(csrf -> csrf.disable());//csrf被禁用了

        // 采用登录表单（用户名+密码）
        // http.formLogin(withDefaults());
        // 认证方式采用基础的认证方式（用户名+密码），实际是弹窗的形式
        // http.httpBasic(withDefaults());

        // 返回新的过滤器链
        return http.build();
    }

}
